/**@author: Administrator
 * @date: 2013-2-21
 * @Description:
 */
package org.benxiong.iplay;

import org.benxiong.iplay.service.NetworkListener;
import org.benxiong.iplay.util.GlobalVar;

import android.app.Application;
import android.content.Context;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * @author Administrator
 * 
 */
public class IplayApp extends Application {
	private NetworkListener				mListener;

	@Override
	public void onCreate() {
		super.onCreate();

		GlobalVar.appContext = this;

		ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
		GlobalVar.isNetworkConnected = activeNetInfo == null ? false : activeNetInfo.isConnected();

		mListener = new NetworkListener();
		IntentFilter iFilter = new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE");

		this.registerReceiver(mListener, iFilter);
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
 
		unregisterReceiver(mListener);
	}

}
